package com.goldstone.actions;

import java.util.List;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.PropertyFilter;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.goldstone.entity.Order;
import com.goldstone.entity.Product;
import com.goldstone.service.OrderService;
import com.goldstone.service.ProductService;

@Namespace("/order")
@Results( { @Result(name = CrudActionSupport.RELOAD, location = "order.do", type = "redirect") })
public class OrderAction extends CrudActionSupport<Order> {
	
	private static final long serialVersionUID = -6456145401441423430L;
	
	@Autowired
	OrderService service;
	
	private Order order;
	@Override
	public String list() throws Exception {
		List<PropertyFilter> filters = PropertyFilter.buildFromHttpRequest(Struts2Utils.getRequest());
		service.find(getPage(), filters);
		return "list";
	}
	@Override
	public String input() throws Exception {
		logger.warn("input");
		return INPUT;
	}
	@Override
	public String save() throws Exception {
		service.save(order);
		return list();
	}
	@Override
	public String delete() throws Exception {
		service.delete(order.getId());
		return list();
	}
	@Override
	protected void prepareModel() throws Exception {
		if(order != null && order.getId() != null) {
			order = service.get(order.getId());
		} else {
			order = new Order();
		}
		
	}
	public Order getOrder() {
		return order;
	}
	public void setOrder(Order order) {
		this.order = order;
	}
	
}
